package com.fqdf.framework.android.activity;


import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;

import com.fqdf.framework.android.R;


public class BaseTitleActivity extends MyBaseActivity {

    private Toolbar mToolBar;

    protected void initToolbar(Toolbar toolbar) {
        this.mToolBar = toolbar;
        if (getActionBarMenu() > 0) {

            mToolBar.inflateMenu(getActionBarMenu());
            toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    int menuItemId = item.getItemId();
                    return true;
                }
            });
        }

    }

    protected int getActionBarMenu() {
        return 0;
    }

    /**
     * 处理点击返回按钮逻辑
     *
     * @return
     */
    protected void onBackClick() {
        finish();
    }

//    protected boolean onSearchClick() {
//        return true;
//    }

    protected void setToolbarTitle(String title) {
        if (mToolBar != null) {
            mToolBar.setTitle(title);
        }
    }

    protected void setToolbarTitle(int titleRes) {
        if (mToolBar != null) {
            mToolBar.setTitle(titleRes);
        }
    }

    /**
     * 设置返回按钮
     *
     * @param status
     */
    protected void setBackBtnStatus(boolean status) {
        if (mToolBar != null) {
            if (status) {
                mToolBar.setNavigationIcon(R.drawable.ic_actionbar_back);
                mToolBar.setNavigationOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onBackClick();
                    }
                });
            }
        }
    }

    protected Toolbar getToolBar() {
        return mToolBar;
    }

}
